//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 
// 	FILE:		transformer.h
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#ifndef TRANSFORMER_H
#define TRANSFORMER_H


//-- INCLUDES ------------------------------------------------------------------------------------------------------------

#include <OpenMesh/Core/Geometry/VectorT.hh>
#include <QtOpenGL/qgl.h>

using namespace OpenMesh;
const float PI = 3.14159265;


//-- CLASS DECLARATION --------------------------------------------------------------------------------------------------
class Transformer
{	

 public:

	 Transformer() {}
	~Transformer() {}/* default destructor  */


	//-- PUBLIC MEMBERS AND FUNCTIONS ------------------------------------------------------------

	GLdouble	projectionMatrix[16],
				modelviewMatrix[16];


	void storeLastPoint			( QPoint _lastPoint );
	void updateProjectionMatrix	( );								 /* updates projection matrix */
	void setDimensions			( GLfloat w, GLfloat h );
	void setInits				( float _rad, float _fov );
	void setLastPointOK			( bool _set ) { lastPointOK = _set; }
	void setOrigScenePosition	( const Vec3f& _cog, float _radius );
	void resetPosition			( );
	void setScenePosition		( const Vec3f& _cog, float _radius );/* Sets the center and size of the whole scene. 
																	 The _center is used as fixpoint for rotations and 
																	 for adjusting the camera/viewer (see viewAll()). */
	void	getModelview		( GLdouble* result );
	void	setModelview		( GLdouble matrix[] );

	//-- TRANSFORMATION FUNCTIONS ------------------------------------------------------------

	void activateRotate			( const QPoint& );
	void moveXY					( const QPoint& newPoint2D );
	void zoom					( float delta );
	

	//-- PROTECTED FUNCTIONS -----------------------------------------------------------------

protected:
	
	bool mapToSphere ( const QPoint& point, Vec3f& result ); /* virtual trackball: map 2D screen point to unit sphere */
	void rotate		 ( const Vec3f& _axis, float _angle );	 /* rotate the scene and update modelview matrix */
	void translate	 ( const Vec3f& _trans);				 /* translate the scene and update modelview matrix */
	void viewAll	 ( ); /* view the whole scene: the eye point is moved far enough from the center so that 
						  the whole scene is visible. */


	//-- PRIVATE DATA MEMBERS FUNCTIONS ------------------------------------------------------

private:
	GLfloat		width, height;

	float		trackRadius;
	QPoint		lastPoint2D;
	Vec3f		lastPoint3D;
	bool		lastPointOK;

	float		fov;
	Vec3f		center;
	float		radius;
	Vec3f		origCenter;
	float		origRadius;
};

#endif